﻿using DuiBa;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Top.PointStore.Business;

namespace DuibaRefreshStateWindowsService
{
    public class DuibaJob:IJob
    {
        /// <summary>
        /// 定时查询兑吧订单状态任务
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            var orders = DuibaOrderManager.GetOutTimeOrder().Result;
            foreach (var order in orders)
            {
                try
                {
                    var rel = DuiBaSDK.GetOrderStatus(order.DuibaOrderNum, order.Kid.ToString());
                    bool temp;
                    if (rel.Success)
                    {
                        switch (rel.Status)
                        {
                            case DuiBa.Models.DuiBaOrderStatus.Fail:
                                temp = DuibaOrderManager.UpdateState(order.Kid, DuibaOrderEnum.Fail).Result;
                                break;
                            case DuiBa.Models.DuiBaOrderStatus.Success:
                                temp = DuibaOrderManager.UpdateState(order.Kid, DuibaOrderEnum.Success).Result;
                                break;
                            default:
                                break;
                        }
                    }
                    else
                    {
                        temp = DuibaOrderManager.UpdateState(order.Kid, DuibaOrderEnum.Fail).Result;
                    }
                }
                catch
                {

                }
            }
        }
    }
}
